#include <QCoreApplication>
#include "qglobal.h"
#include <iostream>

void printf_arr(quint8 *data, int len, quint8 base_num )
{
    while(len--)
    {
        if(10 == base_num)
        {
            printf("%d ",*(data++));
        }
        if(16 == base_num)
        {
            printf("%02X ",*(data++));
        }
    }
    printf("\n");
}

struct Frame_big
{
   quint8 stc;
   quint32 said_u32;
   quint32 taid_u32;
};

struct Frame_small
{
   quint8 stc;
   quint8 said[4];
   quint8 taid[4];
};

struct Frame_union
{
   quint8 stc;
   union
   {
       quint8 said[4];
       quint32 said_u32;
   };
   union
   {
       quint8 taid[4];
       quint32 taid_u32;
   };
};




int main()
{
    struct Frame_big frame_big;
    struct Frame_small frame_small;
    struct Frame_union frame_union;


    printf("sizeof(frame_big)=%d\n", sizeof(frame_big));
    printf("sizeof(frame_small)=%d\n", sizeof(frame_small));
    printf("sizeof(frame_union)=%d\n\n", sizeof(frame_union));


    printf("frame_big.stc addr =%d\n", (quint32)(&frame_big.stc));
    printf("frame_big.said_u32 addr =%d\n", (quint32)(&frame_big.said_u32));
    printf("frame_big.taid_u32 addr =%d\n\n", (quint32)(&frame_big.taid_u32));


    printf("frame_small.stc addr =%d\n", (quint32)(&frame_small.stc));
    printf("frame_small.said addr =%d\n", (quint32)(&frame_small.said));
    printf("frame_small.taid addr =%d\n\n", (quint32)(&frame_small.taid));


    printf("frame_union.stc addr =%d\n", (quint32)(&frame_union.stc));
    printf("frame_union.said addr =%d\n", (quint32)(&frame_union.said));
    printf("frame_union.said_32 addr =%d\n", (quint32)(&frame_union.said_u32));
    printf("frame_union.taid addr =%d\n", (quint32)(&frame_union.taid));
    printf("frame_union.taid_u32 addr =%d\n\n", (quint32)(&frame_union.taid_u32));


    quint8 frame[]={0xa5,  0x01,0x02,0x03,0x04,   0x11,0x12,0x13,0x14, 0x21,0x22,0x23,0x24,0x25,0x26,0x27};
    struct Frame_big *pframe_big = (struct Frame_big *)frame;
    printf("pframe_big->said addr=%d\n", (quint32)(&pframe_big->said_u32));
    printf("pframe_big->said =%x\n", pframe_big->said_u32);
    struct Frame_small *pframe_small = (struct Frame_small *)frame;
    printf("pframe_small->said addr=%d\n", (quint32)(pframe_small->said));
    printf("pframe_small->said =");printf_arr(pframe_small->said,4,16);
    printf("(uint32)(pframe_small->said) =0x%08x\n", *(quint32 *)pframe_small->said);

    return 0;
}
